// pages/guide/guide.js

const app = getApp()
var sliderWidth = 60;


Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabs: ["展品定位", "服务设施", "馆外地图"],
    activeIndex: 0,
    sliderOffset: 0,
    sliderLeft: 0,
    activeId: "0",
    listData: [],
    floor_active: "",
    sdfwer: "1",
    scale: 1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          sliderLeft: (res.windowWidth / that.data.tabs.length - sliderWidth) / 2,
          sliderOffset: res.windowWidth / that.data.tabs.length * that.data.activeIndex
        });
      }
    });
    wx.showLoading({
      title: '加载中',
    });
    //地图数据请求
    that.map_list();
    that.poiListRequest();
  },

  tabClick: function (e) {
    var that = this;
    if (e.currentTarget.id == 2) {
      console.log("跳转馆外地图");
      that.outdoorMap();
    }else {
      this.setData({
        sliderOffset: e.currentTarget.offsetLeft,
        activeIndex: e.currentTarget.id
      });
    }
  },

  //地图数据请求
  map_list() {
    let that = this;
    wx.request({
      url: app.globalData.globalUrl + "map_list",
      data: {
        p: "w",
        language: "1",
        floor_id: "0",
      },
      method: "GET",
      header: {
        'Accept': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res.data);
        var sdf = res.data.data;
        wx.hideLoading();
        if (res.data.status == 1) {
          that.setData({
            floor_datas: sdf,
            floor_active: sdf[0],
            floor_id: sdf[0].floor_id,
            height: sdf[0].height * 750 / sdf[0].width,
          });
        }
      }
    })
  },
  //地图点位请求数据
  poiListRequest() {
    let that = this;
    wx.request({
      url: app.globalData.globalUrl + "exhibit/exhibition_list",
      data: {
        p: 'wx',
      },
      method: 'GET',
      header: {
        'Accept': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res.data);
        wx.hideLoading();
        if (res.data.status == 1) {
          let result = res.data.data;
          that.setData({
            listData: result,
          });
        } else {
          
        }
      },
      fail: () => {
        wx.hideLoading();
        wx.showModal({
          title: "网络繁忙，请稍后再试",
          showCancel: false,
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  // onReady: function () {

  // },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  //搜索
  search(e) {
    var that = this;
    console.log(e.detail.value)
    if (e.detail.value) {
      wx.navigateTo({
        url: '../guide/search?keyword=' + e.detail.value,
      })
    } else {
      wx.showToast({
        title: '请输入展品名称、年代、编号',
        icon: 'none',
        duration: 2000
      })
    }
  },

  outdoorMap() {
    const latitude = 36.826445;
    const longitude = 117.986619;
    wx.openLocation({
      latitude: latitude,
      longitude: longitude,
      scale: 18,
      name:"中国陶瓷琉璃馆",
      address:"山东省淄博市张店区华光路320号"
    })
  },

  //切换楼层
  jumps: function (e) { 
    var that = this;
    var a = e.currentTarget.dataset.id;
    that.setData({
      sdfwer: 1,
      scale: 1
    });
    if (that.data.floor_id == a) {
      // console.log("jsf")
      that.setData({
        floor: !that.data.floor,
      });
    } else {
      for (var i = 0; i < that.data.floor_datas.length; i++) {
        if (a == that.data.floor_datas[i].floor_id) {
          that.setData({
            sheshiActie: false,
            floor_id: a,
            floor_active: that.data.floor_datas[i],
            floor: !that.data.floor,
            height: that.data.floor_datas[i].height * 750 / that.data.floor_datas[i].width,
            pointX: '',
          });

        }
      }
    }
  },

  movablescale: function (e) {
    var that = this;
    if (that.data.exhibition_active && that.data.exhibition_active.png_path) {
      that.data.exhibition_active.img_svg_new = that.data.exhibition_active.png_path + '?' + new Date().getTime();
      that.setData({
        exhibition_active: that.data.exhibition_active,
      })
    }

    that.setData({
      scale: 1 / e.detail.scale,
      imgLoads: false,
    })

  },

})